//
//  ViewController.m
//  cycleControlExtension
//
//  Created by ddy on 2018/8/8.
//  Copyright © 2018年 ddy. All rights reserved.
//

#import "ViewController.h"
#import "CyclePlaceHolderTextField.h"
#import "CycleNotificationTextField.h"
#import "CycleHorButton.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet CyclePlaceHolderTextField *textField;
@property (weak, nonatomic) IBOutlet CycleNotificationTextField *notificationField;
@property(nonatomic, strong) CycleHorButton *horBtn;
@end

@implementation ViewController
- (CycleHorButton *)horBtn {
    if (!_horBtn) {
        _horBtn = [CycleHorButton buttonWithType:UIButtonTypeCustom];
        [_horBtn setImage:[UIImage imageNamed:@"icon_cart_unselect"] forState:UIControlStateNormal];
        [_horBtn setImage:[UIImage imageNamed:@"icon_cart_select"] forState:UIControlStateSelected];
        [_horBtn setTitle:@"按金额" forState:UIControlStateNormal];
        [_horBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_horBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
        _horBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        _horBtn.btnW = 14;
        [_horBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _horBtn;
}
- (void)click:(UIButton *)btn {
    btn.selected = !btn.selected;
    if (btn.selected) {
        btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    } else {
        btn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.horBtn];
    self.horBtn.frame = CGRectMake(100, 300, 71, 30);
    ///文本框
    [self cycle_placeHolderField];
    [self cycle_notificationField];
    ///纯代码版本的
    [self cycle_createField];
}
///placeHolder的field
- (void)cycle_placeHolderField {
    self.textField.c_placeHolderNormalColor = [UIColor lightGrayColor];
    self.textField.c_placeHolderNormalFont = [UIFont systemFontOfSize:16];
    self.textField.c_tintX = 8;
    
    self.textField.c_placeHolderHightLightedColor = [UIColor lightGrayColor];
    self.textField.c_placeHolderHightLightedFont = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    
    self.textField.c_isEditingColor = [UIColor blackColor];
    self.textField.c_isEditingFont = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
}
///notificationField
- (void)cycle_notificationField {
    self.notificationField.c_placeHolderNormalColor = [UIColor lightGrayColor];
    self.notificationField.c_placeHolderNormalFont = [UIFont systemFontOfSize:16];
    self.notificationField.c_tintX = 8;
    
    self.notificationField.c_placeHolderHightLightedColor = [UIColor lightGrayColor];
    self.notificationField.c_placeHolderHightLightedFont = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    
    self.notificationField.c_isEditingColor = [UIColor blackColor];
    self.notificationField.c_isEditingFont = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
}
///纯代码版本的
- (void)cycle_createField {
    CyclePlaceHolderTextField *textField = [[CyclePlaceHolderTextField alloc]init];
    [self.view addSubview:textField];
    textField.frame = CGRectMake(100, 360, 200, 34);
    textField.placeholder = @"请输入";
    textField.text = @"111";
    textField.c_placeHolderNormalColor = [UIColor lightGrayColor];
    textField.c_placeHolderNormalFont = [UIFont systemFontOfSize:16];
    textField.c_placeHolderHightLightedColor = textField.c_placeHolderNormalColor;
    textField.c_placeHolderHightLightedFont = textField.c_placeHolderNormalFont;
    textField.c_isEditingFont = [UIFont systemFontOfSize:16];
    textField.c_isEditingColor = [UIColor blackColor];
    textField.keyboardType = UIKeyboardTypeDecimalPad;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.textAlignment = NSTextAlignmentCenter;
    textField.c_tintX = 8;
    textField.layer.cornerRadius = 1;
    textField.layer.masksToBounds = YES;
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [UIColor colorWithRed:238/255.0 green:240/255.0 blue:240/255.0 alpha:1].CGColor;
    textField.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:250/255.0 alpha:1];
    [textField becomeFirstResponder];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

@end
